/**
 * 报表设计公司(2011)
 */
package com.reportgear.designer.ui.base;

import java.awt.Component;
import java.awt.Dimension;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileFilter;
import java.util.Hashtable;

import javax.swing.JFileChooser;
import javax.swing.JScrollPane;

import com.reportgear.report.core.background.ImagePreviewPane;

/**
 * @version 1.0 2011-3-25
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since ANNCSR 2.0
 */
public class ImageFileChooser extends JFileChooser {

	private ImagePreviewPane imagePreviewPane = new ImagePreviewPane();
	private PropertyChangeListener imagePropertyChangeListener = new PropertyChangeListener() {

		public void propertyChange(PropertyChangeEvent paramPropertyChangeEvent) {
			String str = paramPropertyChangeEvent.getPropertyName();
			if ((!(str.equals("SelectedFileChangedProperty"))) || (!(ImageFileChooser.this.isShowing()))) {
				return;
			}
			// Image localImage = BaseUtils.readImage(((File)
			// paramPropertyChangeEvent.getNewValue()).getPath());
			// ImageFileChooser.this.imagePreviewPane.setImage(localImage);
			// ImageFileChooser.this.imagePreviewPane.repaint();
		}
	};

	public ImageFileChooser() {
		this.imagePreviewPane.setPreferredSize(new Dimension(240, 240));
		this.imagePreviewPane.addPropertyChangeListener(this.imagePropertyChangeListener);
		setAccessory(new JScrollPane(this.imagePreviewPane));
		// ExampleFileFilter localExampleFileFilter = new ExampleFileFilter(new
		// String[]{"jpg", "gif", "png", "bmp"},
		// Inter.getLocText("Image-Image_Files"));
		// localExampleFileFilter.setExtensionListInDescription(true);
		// addChoosableFileFilter(localExampleFileFilter);
		// setAcceptAllFileFilterUsed(false);
		// ChooseFileView localChooseFileView = new ChooseFileView();
		// localChooseFileView.putIcon("jpg",
		// BaseUtils.readIcon("/com/fr/dialog/images/file/jpgFile.gif"));
		// localChooseFileView.putIcon("gif",
		// BaseUtils.readIcon("/com/fr/dialog/images/file/gifFile.gif"));
		// localChooseFileView.putIcon("png",
		// BaseUtils.readIcon("/com/fr/dialog/images/file/pngFile.png"));
		// localChooseFileView.putIcon("bmp",
		// BaseUtils.readIcon("/com/fr/dialog/images/file/bmpFile.gif"));
		// setFileView(localChooseFileView);
	}

	public int showDialog(Component paramComponent, String paramString) {
		this.imagePreviewPane.setImage(null);
		return super.showDialog(paramComponent, paramString);
	}

	class ExampleFileFilter implements FileFilter {

		private Hashtable filters;
		private String description;
		private String fullDescription;
		private boolean useExtensionsInDescription;

		public ExampleFileFilter() {
			this.filters = null;
			this.description = null;
			this.fullDescription = null;
			this.useExtensionsInDescription = true;
			this.filters = new Hashtable();
		}

		public ExampleFileFilter(String paramString) {
			this(paramString, null);
		}

		public ExampleFileFilter(String paramString1, String paramString2) {
			if (paramString1 != null) {
				addExtension(paramString1);
			}
			if (paramString2 == null) {
				return;
			}
			setDescription(paramString2);
		}

		public ExampleFileFilter(String[] paramArrayOfString) {
			this(paramArrayOfString, null);
		}

		public ExampleFileFilter(String[] paramArrayOfString, String paramString) {
			this();
			for (int i = 0; i < paramArrayOfString.length; ++i) {
				addExtension(paramArrayOfString[i]);
			}
			if (paramString == null) {
				return;
			}
			setDescription(paramString);
		}

		public boolean accept(File paramFile) {
			// if (paramFile == null) {
			// break label40;
			// }
			// if (paramFile.isDirectory()) {
			// return true;
			// }
			// String str = getExtension(paramFile);
			// label40:
			// return ((str == null) ||
			// (this.filters.get(getExtension(paramFile)) == null));
			return false;
		}

		public String getExtension(File paramFile) {
			// if (paramFile != null) {
			// String str = paramFile.getName();
			// int i = str.lastIndexOf(46);
			// if ((i > 0) && (i < str.length() - 1)) {
			// return str.substring(i + 1).toLowerCase();
			// }
			// }
			return null;
		}

		public void addExtension(String paramString) {
			if (this.filters == null) {
				this.filters = new Hashtable(5);
			}
			this.filters.put(paramString.toLowerCase(), this);
			this.fullDescription = null;
		}

		public String getDescription() {
			return "ddd";
		}

		public void setDescription(String paramString) {
			this.description = paramString;
			this.fullDescription = null;
		}

		public void setExtensionListInDescription(boolean paramBoolean) {
			this.useExtensionsInDescription = paramBoolean;
			this.fullDescription = null;
		}

		public boolean isExtensionListInDescription() {
			return this.useExtensionsInDescription;
		}
	}

}
